home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 19 / Amiga Plus Leser CD 19.iso / Tools / MorphOS / cvs-1.11.2 / source / amiga / netinclude / netinet / ip_nat.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-11-18  |  6.3 KB  |  238 lines

  1. /*
  2.  * Copyright (C) 1993-2001 by Darren Reed.
  3.  *
  4.  * The author accepts no responsibility for the use of this software and
  5.  * provides it on an ``as is'' basis without express or implied warranty.
  6.  *
  7.  * Redistribution and use, with or without modification, in source and binary
  8.  * forms, are permitted provided that this notice is preserved in its entirety
  9.  * and due credit is given to the original author and the contributors.
  10.  *
  11.  * The licence and distribution terms for any publically available version or
  12.  * derivative of this code cannot be changed. i.e. this code cannot simply be
  13.  * copied, in part or in whole, and put under another distribution licence
  14.  * [including the GNU Public Licence.]
  15.  *
  16.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  17.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  20.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  22.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26.  * SUCH DAMAGE.
  27.  */
  28.  
  29. #ifndef    _NETINET_IP_NAT_H
  30. #define    _NETINET_IP_NAT_H
  31.  
  32. #ifndef _NETINET_IP_FIL_H
  33. #include <netinet/ip_fil.h>
  34. #endif /* _NETINET_IP_FIL_H */
  35.  
  36. #define    SIOCADNAT    _IOW('r', 60, struct ipnat *)
  37. #define    SIOCRMNAT    _IOW('r', 61, struct ipnat *)
  38. #define    SIOCGNATS    _IOWR('r', 62, struct natstat *)
  39. #define    SIOCGNATL    _IOWR('r', 63, struct natlookup *)
  40.  
  41. #define    APR_LABELLEN    16
  42.  
  43. struct ap_session;
  44.  
  45. typedef    struct    nat    {
  46.     ULONG    nat_age;
  47.     LONG    nat_flags;
  48.     ULONG    nat_sumd[2];
  49.     ULONG    nat_ipsumd;
  50.     APTR    nat_data;
  51.     struct    ap_session    *nat_aps;        /* proxy session */
  52.     struct    frentry    *nat_fr;    /* filter rule ptr if appropriate */
  53.     struct    in_addr    nat_inip;
  54.     struct    in_addr    nat_outip;
  55.     struct    in_addr    nat_oip;    /* other ip */
  56.     ULONG    nat_pkts;
  57.     ULONG    nat_bytes;
  58.     UWORD    nat_oport;        /* other port */
  59.     UWORD    nat_inport;
  60.     UWORD    nat_outport;
  61.     UWORD    nat_use;
  62.     UBYTE    nat_tcpstate[2];
  63.     UBYTE    nat_p;            /* protocol for NAT */
  64.     struct    ipnat    *nat_ptr;    /* pointer back to the rule */
  65.     struct    hostmap    *nat_hm;
  66.     struct    nat    *nat_next;
  67.     struct    nat    *nat_hnext[2];
  68.     struct    nat    **nat_phnext[2];
  69.     APTR    nat_ifp;
  70.     LONG    nat_dir;
  71.     UBYTE    nat_ifname[IFNAMSIZ];
  72. } nat_t;
  73.  
  74. typedef    struct    ipnat    {
  75.     struct    ipnat    *in_next;
  76.     struct    ipnat    *in_rnext;
  77.     struct    ipnat    **in_prnext;
  78.     struct    ipnat    *in_mnext;
  79.     struct    ipnat    **in_pmnext;
  80.     APTR    in_ifp;
  81.     APTR    in_apr;
  82.     ULONG    in_space;
  83.     ULONG    in_use;
  84.     ULONG    in_hits;
  85.     struct    in_addr    in_nextip;
  86.     UWORD    in_pnext;
  87.     UWORD    in_ippip;    /* IP #'s per IP# */
  88.     ULONG    in_flags;    /* From here to in_dport must be reflected */
  89.     UWORD    in_spare;
  90.     UWORD    in_ppip;    /* ports per IP */
  91.     UWORD    in_port[2];    /* correctly in IPN_CMPSIZ */
  92.     struct    in_addr    in_in[2];
  93.     struct    in_addr    in_out[2];
  94.     struct    in_addr    in_src[2];
  95.     struct    frtuc    in_tuc;
  96.     LONG    in_redir; /* 0 if it's a mapping, 1 if it's a hard redir */
  97.     UBYTE    in_ifname[IFNAMSIZ];
  98.     UBYTE    in_plabel[APR_LABELLEN];    /* proxy label */
  99.     UBYTE    in_p;    /* protocol */
  100. } ipnat_t;
  101.  
  102. #define    in_pmin        in_port[0]    /* Also holds static redir port */
  103. #define    in_pmax        in_port[1]
  104. #define    in_nip        in_nextip.s_addr
  105. #define    in_inip        in_in[0].s_addr
  106. #define    in_inmsk    in_in[1].s_addr
  107. #define    in_outip    in_out[0].s_addr
  108. #define    in_outmsk    in_out[1].s_addr
  109. #define    in_srcip    in_src[0].s_addr
  110. #define    in_srcmsk    in_src[1].s_addr
  111. #define    in_scmp        in_tuc.ftu_scmp
  112. #define    in_dcmp        in_tuc.ftu_dcmp
  113. #define    in_stop        in_tuc.ftu_stop
  114. #define    in_dtop        in_tuc.ftu_dtop
  115. #define    in_sport    in_tuc.ftu_sport
  116. #define    in_dport    in_tuc.ftu_dport
  117.  
  118. #define    NAT_OUTBOUND    0
  119. #define    NAT_INBOUND    1
  120.  
  121. #define    NAT_MAP        0x01
  122. #define    NAT_REDIRECT    0x02
  123. #define    NAT_BIMAP    (NAT_MAP|NAT_REDIRECT)
  124. #define    NAT_MAPBLK    0x04
  125. /* 0x100 reserved for FI_W_SPORT */
  126. /* 0x200 reserved for FI_W_DPORT */
  127. /* 0x400 reserved for FI_W_SADDR */
  128. /* 0x800 reserved for FI_W_DADDR */
  129. /* 0x1000 reserved for FI_W_NEWFR */
  130.  
  131. #define    MAPBLK_MINPORT    1024    /* don't use reserved ports for src port */
  132. #define    USABLE_PORTS    (65536 - MAPBLK_MINPORT)
  133.  
  134. #define    IPN_CMPSIZ    (sizeof(ipnat_t) - offsetof(ipnat_t, in_flags))
  135.  
  136. typedef    struct    natlookup {
  137.     struct    in_addr    nl_inip;
  138.     struct    in_addr    nl_outip;
  139.     struct    in_addr    nl_realip;
  140.     LONG    nl_flags;
  141.     UWORD    nl_inport;
  142.     UWORD    nl_outport;
  143.     UWORD    nl_realport;
  144. } natlookup_t;
  145.  
  146.  
  147. typedef struct  nat_save    {
  148.     APTR        ipn_next;
  149.     struct    nat    ipn_nat;
  150.     struct    ipnat    ipn_ipnat;
  151.     struct    frentry ipn_fr;
  152.     LONG    ipn_dsize;
  153.     UBYTE    ipn_data[4];
  154. } nat_save_t;
  155.  
  156. #define    ipn_rule    ipn_nat.nat_fr
  157.  
  158. typedef    struct    natget    {
  159.     APTR    ng_ptr;
  160.     LONG    ng_sz;
  161. } natget_t;
  162.  
  163.  
  164. typedef    struct    hostmap    {
  165.     struct    hostmap    *hm_next;
  166.     struct    hostmap    **hm_pnext;
  167.     struct    ipnat    *hm_ipnat;
  168.     struct    in_addr    hm_realip;
  169.     struct    in_addr    hm_mapip;
  170.     LONG    hm_ref;
  171. } hostmap_t;
  172.  
  173.  
  174. typedef    struct    natstat    {
  175.     ULONG    ns_mapped[2];
  176.     ULONG    ns_rules;
  177.     ULONG    ns_added;
  178.     ULONG    ns_expire;
  179.     ULONG    ns_inuse;
  180.     ULONG    ns_logged;
  181.     ULONG    ns_logfail;
  182.     ULONG    ns_memfail;
  183.     ULONG    ns_badnat;
  184.     nat_t    **ns_table[2];
  185.     hostmap_t **ns_maptable;
  186.     ipnat_t    *ns_list;
  187.     APTR    ns_apslist;
  188.     ULONG    ns_nattab_sz;
  189.     ULONG    ns_rultab_sz;
  190.     ULONG    ns_rdrtab_sz;
  191.     ULONG    ns_hostmap_sz;
  192.     nat_t    *ns_instances;
  193.     ULONG    ns_wilds;
  194. } natstat_t;
  195.  
  196. #define    IPN_ANY        0x000
  197. #define    IPN_TCP        0x001
  198. #define    IPN_UDP        0x002
  199. #define    IPN_TCPUDP    (IPN_TCP|IPN_UDP)
  200. #define    IPN_DELETE    0x004
  201. #define    IPN_ICMPERR    0x008
  202. #define    IPN_RF        (IPN_TCPUDP|IPN_DELETE|IPN_ICMPERR)
  203. #define    IPN_AUTOPORTMAP    0x010
  204. #define    IPN_IPRANGE    0x020
  205. #define    IPN_USERFLAGS    (IPN_TCPUDP|IPN_AUTOPORTMAP|IPN_IPRANGE|IPN_SPLIT|\
  206.              IPN_ROUNDR|IPN_FILTER|IPN_NOTSRC|IPN_NOTDST|IPN_FRAG)
  207. #define    IPN_FILTER    0x040
  208. #define    IPN_SPLIT    0x080
  209. #define    IPN_ROUNDR    0x100
  210. #define    IPN_NOTSRC    0x080000
  211. #define    IPN_NOTDST    0x100000
  212. #define    IPN_FRAG    0x200000
  213.  
  214.  
  215. typedef    struct    natlog {
  216.     struct    in_addr    nl_origip;
  217.     struct    in_addr    nl_outip;
  218.     struct    in_addr    nl_inip;
  219.     UWORD    nl_origport;
  220.     UWORD    nl_outport;
  221.     UWORD    nl_inport;
  222.     UWORD    nl_type;
  223.     LONG    nl_rule;
  224.     ULONG    nl_pkts;
  225.     ULONG    nl_bytes;
  226.     UBYTE    nl_p;
  227. } natlog_t;
  228.  
  229.  
  230. #define    NL_NEWMAP    NAT_MAP
  231. #define    NL_NEWRDR    NAT_REDIRECT
  232. #define    NL_NEWBIMAP    NAT_BIMAP
  233. #define    NL_NEWBLOCK    NAT_MAPBLK
  234. #define    NL_FLUSH    0xfffe
  235. #define    NL_EXPIRE    0xffff
  236.  
  237. #endif /* _NETINET_IP_NAT_H */
  238.